<?php

require_once(ABSPATH . 'manage/main.php');

class Project extends Main {
	
	function Project() {
		parent::Main();	
		$this->database();
		$this->lib('session', 'message');
	}

	function init_add() {
		$service_list = $this->db->find_all('service');
		$data = array(
			'service_list' => $service_list
		);
		$this->manage_view('manage/project/project_add', $data);
	}
	
	function add() {
		$this->lib('upload');
		$data = array(
			'name' => $_POST['name'],
			'picture_path' => $this->upload->do_upload('project_image', 'uploads/'),
			'content' => $_POST['content']
		);
		$project_id = $this->db->insert('project', $data);
		
		$service_id_array = explode(",", $_POST('service_id_string'));
		
		foreach($service_id_array as $service_id) {
			$data = array(
				'service_id' => $service_id,
				'project_id' => $project_id
			);
			$this->db->insert('service_project', $data);
		}
		$this->message->set('添加工程成功');
		$this->manage_view('manage/project/project_options');
	}
}

?>